<template>
	<view>
		<view class="u-p-30" style="padding-top: 50rpx;">
			<view class="u-flex u-row-between u-col-top">
				<view @click="$u.route('/subcontract/myscore/mycode/mycode?type=score')" class="one">
					<view class="u-font-20 u-weight u-m-l-30 u-p-t-70">扫码转赠</view>
					<view class="u-font-20 u-m-l-30 u-m-t-20">
						进入<u-icon name='arrow-right' size='20'></u-icon>
					</view>
				</view>
				<view class="u-font-28 u-text-right u-weight" @click="$u.route('/subcontract/myscore/massage/massage')">
					转赠记录</view>
			</view>
			<view class=" u-m-t-30 u-weight u-p-l-40" style="border-left: 6rpx solid #FF782C;color: #1C1C1C;">账号转赠
			</view>

			<view class="u-m-t-30">
				<u-field v-model="mobile" maxlength="11" @blur="get_member_by_mobile" label="转赠好友" placeholder="请填写手机号">
				</u-field>
			</view>

			<view class="u-m-t-30">
				<u-field v-model="money" label="转赠积分" placeholder="请输入转赠积分">
				</u-field>
			</view>

			<view v-if="info.name" class="u-p-20 u-b-r-16 u-flex u-row-between" style="background-color: #F5F5F5;">
				<view class="u-flex">
					<u-image :src="info.avatar" width='78rpx' height='78rpx' shape="circle"></u-image>
					<view class="u-p-l-20">
						<view class="">
							{{info.name}}
						</view>
						<view class="u-font-26 u-m-t-10">
							{{info.mobile}}
						</view>
					</view>
				</view>
			</view>

			<view class="u-m-t-30 u-flex u-m-l-20 u-font-28" style="color: #898989;">
				<view class="">可用积分:</view>
				<view class=" u-flex -m-l-10">
					<view class="u-h-40">
						<u-image src="https://www.sqkjkj.vip/wxImg/common/shop/money.png" mode="aspectFill"
							width="22rpx" height='22rpx'></u-image>
					</view>

					<view class="" style="color: #FF5502FF;">{{score}}</view>
				</view>

			</view>
		</view>
		<!-- 密码弹窗 -->
		<u-popup v-model="show" mode='center'>
			<view class="u-p-30 u-h-200">
				<u-message-input :focus="true" :maxlength='6' @finish="finish"></u-message-input>
			</view>

		</u-popup>
		<!-- @click="$u.route('/pages/my/Recharge/success/success')" -->
		<view class="u-w-600 u-h-100 u-l-h-100 u-text-center u-fix u-b-50 u-m-l-50 u-b-r-13 cl_FFF"
			style="background: linear-gradient(-64deg, #FF382C, #FF633F);" @click="save">提交</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				mobile: "",
				money: '',
				userinfo: '',
				score: 0,
				show: false,
				info: ''
			}
		},
		onLoad(load) {
			if (load.mobile) {
				this.mobile = load.mobile
				this.get_member_by_mobile()
			}
			this.userinfo = uni.getStorageSync("userinfo")
			this.score = this.userinfo.score
		},
		methods: {
			// 点击提交
			save() {
				if (this.mobile.trim() == '' || !(
						/^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/).test(this
						.mobile)) {
					uni.showToast({
						icon: 'none',
						title: "请输入正确手机号码"
					})

				} else if (this.money.trim() == "") {
					uni.showToast({
						icon: 'none',
						title: "请输入转增积分"
					})
				}else if (parseFloat(this.money)<=0) {
					uni.showToast({
						icon: 'none',
						title: '转赠积分不能为0'
					})
				} else if (parseFloat(this.money) > parseFloat(this.userinfo.score)) {
					uni.showToast({
						icon: 'none',
						title: '积分不足'
					})
				} else {
					if (uni.getStorageSync('userinfo').have_trade_pwd == 0) {
						uni.showModal({
							title: '提示',
							content: '请先设置余额支付密码',
							success: (res)=> {
								if (res.confirm) {
									this.$u.route('/pages/changePayPassword/changePayPassword')
								} else {
									
								}
							}
						})
						return
					}
					this.show = true
				}
			},
			get_member_by_mobile() {
				if (this.mobile.length == 11) {
					this.$api.get_member_by_mobile({
						mobile: this.mobile || ''
					}, res => {
						if (res.data.code == 1) {
							if (res.data.data.name) {
								this.info = res.data.data
							} else {
								uni.showToast({
									title: res.data.msg,
									icon: 'none',
									duration: 2000
								})
								this.info = []
							}

						}
					})
				}
			},
			finish(e) {
				this.show = false
				this.pay(e)
			},
			pay(e) {
				this.$api.my_score_give({
					type: 'score',
					category: 1,
					mobile: this.mobile,
					num: this.money,
					tradepwd: e
				}, res => {
					if (res.data.code == 1) {
						uni.showToast({
							icon: 'none',
							title: '转赠成功'
						})
						setTimeout(() => {
							uni.navigateBack()
						}, 500)
					} else {
						uni.showToast({
							icon: 'none',
							title: res.data.msg
						})
					}
				})
			},
			backs() {
				uni.navigateBack()
			}
		}
	}
</script>

<style scoped>
	.one {
		width: 307rpx;
		height: 178rpx;
		background: url('https://www.sqkjkj.vip/wxImg/mybag/img3.png') no-repeat;
		background-size: 100% 100%;
	}

	.one1 {
		width: 307rpx;
		height: 178rpx;
		background: url('https://www.sqkjkj.vip/wxImg/mybag/img2.png') no-repeat;
		background-size: 100% 100%;
	}
</style>
